package com.tandn;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.tandn.activity.show.ShowListAcitvity;
public class ATMLocatorInMapAcivity extends MapActivity
{
	private MapView _mapView = null;
	private GeoPoint _geoPoint = null;
	private Geocoder _geocoder = null;
	private MapController _mapController = null;
	
	@Override
	protected void onCreate(Bundle icicle)
	{
		super.onCreate(icicle);
		setContentView(R.layout.main_map);
		
		_mapView = (MapView) findViewById(R.id.mapviewSearch);
		_geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
		_mapController = _mapView.getController();
		
		final Button listResultsButton = (Button) findViewById(R.id.buttonShowListResults);
		listResultsButton.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0)
			{
				Intent intent = new Intent(ATMLocatorInMapAcivity.this,
						ShowListAcitvity.class);
				startActivity(intent);
			}
		});
		
		List<Address> addressesList;
		try
		{
			addressesList = _geocoder.getFromLocationName("Viet Nam", 1);
			if (addressesList.size() > 0)
			{
				_mapController.animateTo(new GeoPoint(
						(int) (addressesList.get(0).getLatitude() * 1e6),
						(int) (addressesList.get(0).getLongitude() * 1e6)));
			}
		} catch (IOException e)
		{
			e.printStackTrace();
		}
		_mapView.setBuiltInZoomControls(true);
		_mapController.setZoom(7);
		_mapView.invalidate();
	}

	@Override
	protected boolean isRouteDisplayed()
	{
		return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent motionEvent)
	{
		if (motionEvent.getAction() == 1)
		{
			_geoPoint = _mapView.getProjection().fromPixels((int) motionEvent.getX(), (int) motionEvent.getY());
			
		}
		return false;
	}
}
